package controller

import (
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
	"user_bff/forms"
	"user_bff/pkg"
	"user_bff/user_proto"
)

// 用户注册
func UserRegister(c *gin.Context) {
	var form forms.RegisterUserForm
	if err := c.ShouldBind(&form); err != nil {
		ReturnErrorJson(err, c)
	}
	comment := pkg.Comment()
	register, err := comment.UserRegister(context.Background(), &user_proto.UserRegisterRequest{
		NickName: form.NickName,
		Mobile:   form.Mobile,
		Password: form.Password,
	})
	if err != nil {
		HandleGrpcErrorToHttp(err, c)
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "注册成功",
		"data": register,
	})
	return
}
